package com.example.administrator.managesystem.activity.login;

import android.os.CountDownTimer;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.activity.VideoListActivity;
import com.example.administrator.managesystem.base.BaseActivity;
import com.example.administrator.managesystem.bean.BaseEvent;
import com.example.administrator.managesystem.presenter.login.LoginPresenter;
import com.example.administrator.managesystem.ui.LoginView;
import com.example.administrator.managesystem.utils.ActivityUtils;
import com.example.administrator.managesystem.video.LandListActivity;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Administrator on 2019/1/4.
 */

public class OneShotLoginActivity extends BaseActivity implements LoginView {

    private EditText tel_number,verifyCode;
    private TextView login,verify_code_tv;
    private CountDownTimer timer;
    @Override
    public void initView() {
     showfloatButton(false,false);
     tel_number=findViewById(R.id.tel_number);
     verifyCode=findViewById(R.id.verificationCode);
     login=findViewById(R.id.login_tv);
     verify_code_tv=findViewById(R.id.verify_code_tv);
    }

    @Override
    public void doBusiness() {
        verify_code_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new LoginPresenter(OneShotLoginActivity.this).CodeRequest(tel_number.getText().toString(),OneShotLoginActivity.this);
            }
        });

        login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgressDialog();
                new LoginPresenter(OneShotLoginActivity.this).OneLoginRequest(tel_number.getText().toString(),verifyCode.getText().toString(),OneShotLoginActivity.this);
            }
        });

    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_one_shot_login;
    }

    @Override
    public void showMessage(String msg) {
          dismissProgressDialog();
    }

    @Override
    public void navigateToHome() {
        dismissProgressDialog();
        gotoActivity(LandListActivity.class,true);
        BaseEvent event = new BaseEvent();
        event.setCode(0);
        EventBus.getDefault().post(event);


    }

    @Override
    public void startCountDown() {
        timer= new CountDownTimer(60000, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {
                verify_code_tv.setText(millisUntilFinished / 1000 + "s");
                verify_code_tv.setTextColor(getResources().getColor(R.color.white));
                verify_code_tv.setEnabled(false);//设置不可点击
            }

            @Override
            public void onFinish() {
                verify_code_tv.setText("重新获取");
                verify_code_tv.setTextColor(getResources().getColor(R.color.circle_tv));
                verify_code_tv.setEnabled(true);
            }
        };

        timer.start();
    }


}
